const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

/**
 * 数组裂变
 * @param {any[]} array 原数组
 * @param {number} splitCount 个数 原 [1,2,3,4,5,6], 3 --> [[1,2,3], [4,5,6]]
 * @returns
 */
const arraySplit = (array, splitCount) => {
  let index = 0
  let newArray = []
  while (index < array.length) {
    newArray.push(array.slice(index, (index += splitCount)))
  }
  return newArray
}

module.exports = {
  formatTime,
  arraySplit
}
